package com.fxu.gen;

import cn.hutool.core.util.ReflectUtil;
import cn.hutool.core.util.TypeUtil;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.fxu.tpl.entity.Test;

import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.Arrays;

public class Wrappers<T> {
  @FunctionalInterface
  public interface LQuery<T> {
    @SuppressWarnings("varargs")
    LQuery<T> show(SFunction<T, ?>... columns);
  }

  public static <T> LQuery<T> query() {
    Method method = ReflectUtil.getMethodByNameIgnoreCase(Wrappers.class, "query");
    Type type = TypeUtil.getReturnType(method);
    Class<?> cls = TypeUtil.getReturnClass(method);

    System.out.println("type=" + type);
    System.out.println("cls=" + cls + "," + Arrays.toString(cls.getGenericInterfaces()));
    Type type2 = TypeUtil.getTypeArgument(type);
    System.out.println("type2=" + type2.getClass());
    Type type3 = TypeUtil.getActualType(type, type2);
    System.out.println("type3=" + type3);

    return (SFunction<T, ?>... columns) -> {
      System.out.println("11");
      return null;
    };
  }

  public static void main(String[] args) {
    LQuery<Test> lQuery = Wrappers.query();
    lQuery.show(Test::getId);
    System.out.println("lQuery=" + lQuery);
  }
}